﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace Soul.Excel
{
    public class ExcelMergeRegionCollection : List<ExcelMergeRegion>
    {
        internal void AddSafe(ExcelMergeRegion region)
        {
            if (!this.Any(a => a.FirstColumn <= region.FirstColumn && a.LastColumn >= region.LastColumn && a.FirstRow <= region.FirstRow && a.LastRow >= region.LastRow))
            {
                Add(region);
            }
        }

        public void Add(int firstRow, int lastRow, int firstColumn, int lastColumn)
        {
            AddSafe(new ExcelMergeRegion(firstRow, lastRow, firstColumn, lastColumn));
        }

        public void Add(object value,int firstRow, int lastRow, int firstColumn, int lastColumn, Action<ExcelStyle> style)
        {
            AddSafe(new ExcelMergeRegion(value, firstRow, lastRow, firstColumn, lastColumn, style));
        }
    }
}
